<?php
/**
 *
 * @group_name 湖南伯瑞曼科技有限公司
 *
 * @author Master
 *
 * @api ${API}
 *
 * @time 2021/8/28 - 20:59
 *
 */

namespace app\api\middleware;

use app\api\common\Auth;
use app\api\common\common;
use think\facade\Cache;

class CheckLogin
{


    /**
     * @param $request
     * @param \Closure $next
     * @return \think\Response
     */
    public function handle($request, \Closure $next)
    {
        $response = $next($request);

        // 添加中间件执行代码
        $header = $request->header();

        if(empty($header['sign']) && empty($header['token'])){
            $common = new common();
            return $common->result(null,'请先登陆！','100001');
        }

         $signResult = Auth::checkSignkey($header);
        if (!$signResult){
            $common = new common();
            return $common->result(null,$signResult["msg"],'100001');
        }
        $result = Auth::checkToken($header['token']);
        if ($result['code'] == 0){
            $common = new common();
            return $common->result(null,$result["msg"],'100001');
        }
        return $response->header();
    }
}
